package com.hzqy.service.statistics;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.hzqy.persistence.dao.statistics.ActivityDao;
import com.hzqy.persistence.dao.statistics.WeekFreeDao;
import com.hzqy.service.core.GenericServiceBean;
import com.hzqy.web.vo.AwardUserVo;
import com.hzqy.web.vo.PmsUserVo;
import com.hzqy.web.vo.statistics.StatDataUserSextupleVo;
import com.hzqy.web.vo.weekfree.WeekFreeInfoVo;

@Service
public class WeekFreeServiceBean extends GenericServiceBean<PmsUserVo, WeekFreeDao, Integer>{
	private static final long serialVersionUID = 1L;
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private WeekFreeDao weekFreeDao;

	@Override
	public WeekFreeDao getEntityDao() {
		return weekFreeDao;
	}
	
	public Map<String,Object> selectWeekFreeList(WeekFreeInfoVo weekFreeInfoVo, int curPage,
			int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weekFreeDao.selectweekFreeCount(weekFreeInfoVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_wwf_userid", weekFreeInfoVo.getF_wwf_userid());
			map.put("f_wwf_contentid", weekFreeInfoVo.getF_wwf_contentid());
			map.put("f_wwf_starttime", weekFreeInfoVo.getF_wwf_starttime());
			map.put("f_wwf_endtime", weekFreeInfoVo.getF_wwf_endtime());
			map.put("f_wwf_drawtime",weekFreeInfoVo.getF_wwf_drawtime());
			List<WeekFreeInfoVo> results = weekFreeDao.selectweekFreeList(map);
			map.put("rows", results);
		} else {
			map.put("rows", new ArrayList<AwardUserVo>());
		}
		return map;
	}
	public Map<String,Object> selectExcelList(WeekFreeInfoVo weekFreeInfoVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weekFreeDao.selectExcelCount(weekFreeInfoVo);
		String status="";
		map.put("total", rowCount);
		if(rowCount > 0) {
			map.put("f_wwf_id",weekFreeInfoVo.getF_wwf_id() );
			map.put("f_wwf_userid", weekFreeInfoVo.getF_wwf_userid());
			map.put("f_wwf_contentid", weekFreeInfoVo.getF_wwf_contentid());
			map.put("f_wwf_starttime", weekFreeInfoVo.getF_wwf_starttime());
			map.put("f_wwf_endtime", weekFreeInfoVo.getF_wwf_endtime());
			map.put("f_wwf_drawtime", weekFreeInfoVo.getF_wwf_drawtime());
			List<WeekFreeInfoVo> results = weekFreeDao.selectExcelList(map);
			List<WeekFreeInfoVo> resultlists = new ArrayList<WeekFreeInfoVo>(); 
			for(WeekFreeInfoVo auv:results){
				if("1004".equals(auv.getF_wwf_contentid())){
					status="教育";
				} else if("1005".equals(auv.getF_wwf_contentid())){
					status="音乐";
				} else if("1006".equals(auv.getF_wwf_contentid())){
					status="悦生活";
				}
				auv.setF_wwf_contentid(status);
				resultlists.add(auv);
			}
			map.put("rows", resultlists);
		} else {
			map.put("rows", new ArrayList<WeekFreeInfoVo>());
		}
		return map;
	}

	public Map<String, Object> selectCxlyVideoList(StatDataUserSextupleVo sextupleVo, int curPage, int pageSize) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weekFreeDao.selectCxlyVideoCount(sextupleVo);
		map.put("total", rowCount);
		if(rowCount > 0 && curPage > 0 && pageSize > 0) {
			map.put("firstResult", (curPage-1)*pageSize);
			map.put("maxResults", pageSize);
			map.put("f_sdus_serverid", sextupleVo.getF_sdus_serverid());
			map.put("f_sdus_property", sextupleVo.getF_sdus_property());
			List<StatDataUserSextupleVo> results = weekFreeDao.selectCxlyVideoList(map);
			map.put("rows", results);
		}else {
			map.put("rows", new ArrayList<StatDataUserSextupleVo>());
		}
		return map;
	}

	public Map<String, Object> selectVideoExcelList(StatDataUserSextupleVo sextupleVo) {
		Map<String,Object> map = new HashMap<String, Object>();
		Integer rowCount = weekFreeDao.selectCxlyVideoCount(sextupleVo);
		map.put("total", rowCount);
		String property = "";
		String aspect = "";
		if(rowCount > 0) {
			map.put("f_sdus_serverid", sextupleVo.getF_sdus_serverid());
			map.put("f_sdus_property", sextupleVo.getF_sdus_property());
			List<StatDataUserSextupleVo> results = weekFreeDao.selectVideoExcel(map);
			List<StatDataUserSextupleVo> resultlists = new ArrayList<StatDataUserSextupleVo>(); 
			for(StatDataUserSextupleVo vo:results){
				if(1 == vo.getF_sdus_property()){
					property = "勇气";
				}else if(2 == vo.getF_sdus_property()){
					property = "爱心";
				}else if(3 == vo.getF_sdus_property()){
					property = "诚实";
				}else if(4 == vo.getF_sdus_property()){
					property = "纯真";
				}else if(5 == vo.getF_sdus_property()){
					property = "智慧";
				}else if(6 == vo.getF_sdus_property()){
					property = "友情";
				}
				
				if(1 == vo.getF_sdus_min_aspect()){
					aspect = "勇气";
				}else if(2 == vo.getF_sdus_min_aspect()){
					aspect = "爱心";
				}else if(3 == vo.getF_sdus_min_aspect()){
					aspect = "诚实";
				}else if(4 == vo.getF_sdus_min_aspect()){
					aspect = "纯真";
				}else if(5 == vo.getF_sdus_min_aspect()){
					aspect = "智慧";
				}else if(6 == vo.getF_sdus_min_aspect()){
					aspect = "友情";
				}
				vo.setF_sdus_property_name(property);
				vo.setF_sdus_min_aspect_name(aspect);
				resultlists.add(vo);
			}
			map.put("rows", resultlists);
		}else {
			map.put("rows", new ArrayList<StatDataUserSextupleVo>());
		}
		return map;
	}
	
}
